package com.ma.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ma.entity.SysRole;
import com.ma.mapper.SysRoleMapper;
import com.ma.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service;

import javax.management.relation.Role;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 */
@Service
public class SysRoleServiceImpl  implements SysRoleService {
    @Autowired
    private SysRoleMapper sysRoleMapper;

    @Override
    public List<SysRole> selectCodeById(Long id) {
        return sysRoleMapper.selectCodeById(id) ;
    }

    @Override
    public List<SysRole> list() {
        return sysRoleMapper.selectAll();
    }

    @Override
    public  PageInfo<SysRole> listByUsername(String  username,Integer page,Integer rows) {
         //设置分页信息
         PageHelper.startPage(page,rows);
       List<SysRole> sysRoles=sysRoleMapper.listByUsername(username);

        PageInfo<SysRole> pageInfo=new PageInfo<>(sysRoles);

        return pageInfo;
    }

    @Override
    public SysRole selectAllById(Long id) {
        return sysRoleMapper.selectAllById(id);
    }

    @Override
    public void save(SysRole sysRole) {
        sysRoleMapper.save(sysRole);
    }

    @Override
    public void update(SysRole sysRole) {
    sysRoleMapper.update(sysRole);
    }

    @Override
    public void delete(Long id) {
        sysRoleMapper.delete(id);
    }

    @Override
    public List<SysRole> getAllByUserId(Long id) {
        return sysRoleMapper.getAllByUserId(id);
    }
}
